package com.zyz.N_反射机制.获取Class实例;

/**
 * @author: vick
 * @Date: 2025/4/14
 * @Description:
 * @version: 1.0
 */
public class Demo1 {
    public static void main(String[] args) throws ClassNotFoundException {
        //方式一：若已知具体的类，通过类的class属性获取
        Class clazz1 = Demo1.class;

        //方式二：已知某个类的实例，调用该实例的getClass()方法获取Class对象
        //获取实例
        Demo1 demo1 = new Demo1();
        //调用实例的getClass方法
        Class clazz2 = demo1.getClass();

        //方式三：已知一个类的全类名，可通过Class类的静态方法forName()获取
        Class clazz3 = Class.forName("com.vick.N_反射机制.获取Class实例.Demo1");

        //方式四：可以用系统类加载对象或自定义加载器对象加载指定路径下的类型
        Class clazz4
                = ClassLoader.getSystemClassLoader().loadClass("com.vick.N_反射机制.获取Class实例.Demo1");

        System.out.println(clazz1);
        System.out.println(clazz2);
        System.out.println(clazz3);
        System.out.println(clazz4);
        System.out.println(clazz1 == clazz2);
        System.out.println(clazz2 == clazz3);
        System.out.println(clazz3 == clazz4);
    }
}
